//
//  UITextInput.swift
//  fho
//
//  Created by 郭颢源 on 2021/4/1.
//

import Foundation
import UIKit

extension UITextInput
{
    var selectedRange: NSRange?
    {
        if let selectedRange = self.selectedTextRange
        {
           return NSMakeRange(self.offset(from: self.beginningOfDocument, to: selectedRange.start),
                              self.offset(from: selectedRange.start,      to: selectedRange.end))
        }
        else
        {
            return nil
        }
    }
}
